package com.aitaoxue.palx.adapter;

import java.util.HashMap;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.ButterKnife;
import butterknife.InjectView;

import com.aitaoxue.palx.R;
import com.aitaoxue.palx.base.ListBaseAdapter;
import com.aitaoxue.palx.bean.MyCourseList.MyCourse;

public class MyCourseAdapter extends ListBaseAdapter {

	// 保存课程图标的对应关系
	private static HashMap<String, Integer> map;

	public MyCourseAdapter() {
		map = new HashMap<String, Integer>();

		map.put("1", R.drawable.math);
		map.put("2", R.drawable.chinese);
		map.put("3", R.drawable.english);
		map.put("4", R.drawable.biology);
		map.put("5", R.drawable.chemistry);
		map.put("6", R.drawable.physical);
		map.put("7", R.drawable.politics);
		map.put("8", R.drawable.history);
		map.put("9", R.drawable.geogrphy);
		map.put("10", R.drawable.all);
		map.put("11", R.drawable.music);
		map.put("12", R.drawable.art);
		map.put("13", R.drawable.dance);
		map.put("14", R.drawable.language);
		map.put("15", R.drawable.computer);
		map.put("16", R.drawable.hand);
		map.put("17", R.drawable.other);
	}

	@Override
	protected View getRealView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;

		if (convertView == null) {
			convertView = getLayoutInflater(parent.getContext()).inflate(
					R.layout.course_item, null);

			holder = new ViewHolder(convertView);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		MyCourse course = (MyCourse) _data.get(position);
		holder.icon.setImageResource(map.get(course.getGood_logo_id()));
		holder.name.setText(course.getGood_kind_name());
		holder.price.setText("￥" + course.getGood_price() + "/小时");
		holder.num.setText("最低起订数:  " + course.getGood_minnum());

		return convertView;
	}

	class ViewHolder {

		@InjectView(R.id.course_ico)
		ImageView icon;
		@InjectView(R.id.course_name)
		TextView name;
		@InjectView(R.id.course_price)
		TextView price;
		@InjectView(R.id.min_num)
		TextView num;

		public ViewHolder(View view) {
			ButterKnife.inject(this, view);
		}
	}

}
